<template>
    <div v-loading="allLoading">
        <el-card>
        <!--查询条件start --111s-->
        <el-form :inline="true"
                 :model="query"
                 class="query-form"
                 size="small">
            <el-form-item>
                <el-button type="primary" icon="el-icon-edit" @click.native="showDialogAdd(null,null)">添加
                </el-button>
            </el-form-item>
            <el-form-item class="query-form-item">
                <el-input v-model="query.searchParams"
                          placeholder="账号/编码"
                          prefix-icon="el-icon-search"
                          @keyup.enter.native="onSubmit"
                          clearable></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary"
                           icon="el-icon-refresh"
                           @click="onRest"></el-button>
                <el-button type="primary"
                           icon="el-icon-search"
                           @click="onSubmit">查询</el-button>
            </el-form-item>
        </el-form>
        <!--查询条件end-->

        <!--列表start --->
        <el-table ref="multipleTable"
                  v-loading="loading"
                  :data="list"
                  :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
                  @selection-change="handleSelectionChange"
                  border>
            <el-table-column label="序号" prop="userId" width="50" align="center">
                <template slot-scope="scope">
                    <span>{{scope.$index + 1}}</span>
                </template>
            </el-table-column>
            <el-table-column label="公司名称" prop="enterpriseName" align="center"/>
            <el-table-column label="账号" prop="userMobile" width="120" align="center"/>
            <el-table-column label="添加时间" width="180" :show-overflow-tooltip="true"  align="center">
                <template slot-scope="scope">
                    <i class="el-icon-time"
                       v-if="scope.row.userRegistTime!=null"></i>
                    <span v-if="scope.row.userRegistTime!=null">{{ scope.row.userRegistTime | formatDateStr('yyyy-MM-dd hh:mm:ss') }}</span>
                    <span v-else>无</span>
                </template>
            </el-table-column>
            <el-table-column label="当前等级"
                             align="center">
                <template slot-scope="scope">
                    <span v-for="(item,index) in scope.row.realList" :key="index">
                        {{item.companyname}}
                        <span v-if="item.memberlevel==0">普通合伙人</span>
                        <span v-else-if="item.memberlevel==1">高级合伙人</span>
                        <span v-else-if="item.memberlevel==2">首席合伙人</span>

                        <span v-if="item.performancelevel==0">(平台)</span>
                        <span v-else-if="item.performancelevel==1">（全球）</span>
                        <span v-else-if="item.performancelevel==2">（省）</span>
                        <span v-else-if="item.performancelevel==3">（市）</span>
                        <span v-else-if="item.performancelevel==4">（县）</span>
                        <br/>
                    </span>
                </template>
            </el-table-column>
            <el-table-column label="孵化等级"  align="center">
                <template slot-scope="scope">
                    <span v-if="scope.row.isFictitious==1">
                        平台合伙人
                    </span>
                    <span v-else>
                        <span v-if="scope.row.fictitiousList.length>0">
                            <span v-for="(item,index) in scope.row.fictitiousList" :key="index">
                                {{item.companyname}} (孵化)
                                <span v-if="item.companylevel==1">(全球)</span>
                                <span v-if="item.companylevel==2">(省)</span>
                                <span v-if="item.companylevel==3">(市)</span>
                                <span v-if="item.companylevel==4">(县)</span>
                                <br/>
                            </span>
                        </span>
                        <span v-else>-</span>
                    </span>
                </template>

            </el-table-column>
            <el-table-column label="团队数量" width="80" prop="teamNum" align="center"/>
            <el-table-column label="业绩"  width="150" prop="userTotalIntegral" align="center"/>
            <el-table-column label="操作"
                             width="120"
                             align="center"
                             fixed="right">
                <template  slot-scope="scope">
                    <el-button v-if="scope.row.teamNum > 0" type="primary"
                               size="mini"
                               @click.native="showDialogAddOrEdit(scope.row)">查看团队</el-button>
                    <span v-else> - </span>
                </template>
            </el-table-column>
        </el-table>
        <!--列表end --222e-->
        <!--分页模块start-->
        <el-pagination class="pagination-container"
                       background
                       :page-size="query.pageSize"
                       @size-change="handleSizeChange"
                       @current-change="handleCurrentChange"
                       layout="total,sizes,prev, pager, next, jumper"
                       :current-page="query.currentPage"
                       :page-sizes="[5,10, 20, 30, 50]"
                       :total="totalNumber"></el-pagination>
        <!--分页模块end-->

        <!--新增/编辑弹框start--333s-->
        <el-dialog title="孵化团队"
                   :visible.sync="dialogAddOrEdit"
                   width="80%"
                   :before-close="hideDialogAddOrEdit"
                   :close-on-click-modal="false">
            <template slot="title">
                <div class="avue-crud__dialog__header">
                    <span class="el-dialog__title">
                        <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                       孵化团队
                    </span>
                </div>
            </template>
            <el-card>
            <el-form :model="checkQuery"
                     :rules="rules"
                     ref="ruleForm"
                     class="demo-ruleForm"
                     size="small">

                <el-form-item
                    prop="userId">
                    <el-input v-model="checkQuery.searchParams" style="width:400px;margin-right: 20px;" placeholder="账号/编码" clearable></el-input>
                    <el-button type="primary"
                               icon="el-icon-search"
                               @click="onCheckSubmit">查询</el-button>
                </el-form-item>

                <!--列表start --->
                <el-table ref="merchantsgoodslist"
                          v-loading="checkLoading"
                          :data="merchantsgoodslist"
                          :header-cell-style="{background:'#F4F4F5',color:'#606266'}"
                          @selection-change="checkHandleSelectionChange"
                          border>
                    <el-table-column label="序号"
                                     prop="userId"
                                     width="50"
                                     align="center">
                        <template slot-scope="scope">
                            <span>{{scope.$index + 1}}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="公司名称"
                                     prop="enterpriseName"
                                     align="center" />
                    <el-table-column label="公司账号"
                                     prop="userMobile"
                                     width="110"
                                     align="center" />
                    <el-table-column label="注册时间"
                                     prop="userRegistTime"
                                     width="180"
                                     align="center">
                        <template slot-scope="scope">
                            <i class="el-icon-time"
                               v-if="scope.row.userRegistTime!=null"></i>
                            <span v-if="scope.row.userRegistTime!=null">{{ scope.row.userRegistTime | formatDateStr('yyyy-MM-dd hh:mm:ss') }}</span>
                            <span v-else>无</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="当前等级" align="center" >
                        <template slot-scope="scope">
                            <span v-if="scope.row.performanceLevel==5">{{ scope.row.memberLevel==0?'体验商城':'合作商城' }}</span>
                            <span v-else>
                                <span v-for="(item,index) in scope.row.realList" :key="index">
                                    {{item.companyname}}
                                    <span v-if="item.memberlevel==0">普通合伙人</span>
                                    <span v-else-if="item.memberlevel==1">高级合伙人</span>
                                    <span v-else-if="item.memberlevel==2">首席合伙人</span>

                                    <span v-if="item.performancelevel==0">(平台)</span>
                                    <span v-else-if="item.performancelevel==1">（全球）</span>
                                    <span v-else-if="item.performancelevel==2">（省）</span>
                                    <span v-else-if="item.performancelevel==3">（市）</span>
                                    <span v-else-if="item.performancelevel==4">（县）</span>
                                    <br/>
                                </span>
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column label="孵化等级"   align="center" >
                        <template slot-scope="scope">
                            <span v-if="scope.row.performanceLevel==5">{{ scope.row.memberLevel==0?'体验商城':'合作商城' }}</span>
                            <span v-else>
                                <span v-if="scope.row.fictitiousList.length>0">
                                    <span v-for="(item,index) in scope.row.fictitiousList" :key="index">
                                        {{item.companyname}} (孵化)
                                        <span v-if="item.companylevel==1">(全球)</span>
                                        <span v-if="item.companylevel==2">(省)</span>
                                        <span v-if="item.companylevel==3">(市)</span>
                                        <span v-if="item.companylevel==4">(县)</span>
                                        <br/>
                                    </span>
                                </span>
                                <span v-else>-</span>
                            </span>
                        </template>
                    </el-table-column>
                    <el-table-column label="业绩" prop="userTotalIntegral"   width="180" align="center" />
                </el-table>
                <!--分页模块start-->
                <!-- <el-pagination class="pagination-container"
                               background
                               :page-size="checkQuery.pageSize"
                               @size-change="checkHandleSizeChange"
                               @current-change="checkHandleCurrentChange"
                               layout="total,sizes,prev, pager, next, jumper"
                               :current-page="checkQuery.currentPage"
                               :page-sizes="[5,10, 20, 30, 50]"
                               :total="checkTotalNumber"></el-pagination> -->
            </el-form>
            </el-card>
        </el-dialog>
        <!-- 添加孵化团队 -->
        <el-dialog title="新增孵化团队" type="center" :visible.sync="addIncubationTeam" width="50%" :close-on-click-modal="false">
            <template slot="title">
                <div class="avue-crud__dialog__header">
                    <span class="el-dialog__title">
                        <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                       新增孵化团队
                    </span>
                </div>
            </template>
            <el-card>
            <el-form :model="addForm" :rules="addRules" ref="addForm">
                <el-form-item label="添加孵化团队账号：" prop="name">
                    <el-input v-model="addForm.name" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            </el-card>
            <div slot="footer" class="dialog-footer">
                <el-button @click="cancelAddTeam('addForm')">取 消</el-button>
                <el-button type="primary" @click="addTeam('addForm')">确 定</el-button>
            </div>
        </el-dialog>

        <!--新增/编辑弹框start--333s-->
        <el-dialog
            :title="dialogAddOrEditName"
            :visible.sync="dialogAdd"
            width="50%"
            v-loading="allLoading"
            :before-close="hideDialogAddOrEdit" :close-on-click-modal="false">
            <template slot="title">
                <div class="avue-crud__dialog__header">
                    <span class="el-dialog__title">
                        <span style="display:inline-block;background-color: #3478f5;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px"></span>
                       {{dialogAddOrEditName}}
                    </span>
                </div>
            </template>
            <el-card>
            <el-form :model="formAddData" :rules="rules" ref="formAddRules" label-width="100px" class="demo-ruleForm">

                <el-form-item label="用户身份：" prop="IslegalPerson">
                    <el-switch
                        v-model="formAddData.IslegalPerson"
                        active-text="非法人"
                        inactive-text="法人">
                    </el-switch>
                </el-form-item>
                <el-form-item label="用户姓名：" prop="userName">
                    <el-input placeholder="请输入用户姓名" v-model="formAddData.userName"></el-input>
                </el-form-item>
                <el-form-item label="手机号码：" prop="userMobile">
                    <el-input placeholder="请输入手机号码" v-model="formAddData.userMobile"></el-input>
                </el-form-item>
                <el-form-item label="验证码：" prop="userCode" class="pr">
                    <el-input style="width:320px;margin-right: 20px;" v-model="formAddData.userCode" placeholder="验证码有效时间120s">
                    </el-input>
                    <el-button type="button" style="width:120px;" @click="sendcode" :disabled="disabled">{{btntxt}}
                    </el-button>
                </el-form-item>
                <el-form-item label="登录密码：" prop="userPwd">
                    <el-input placeholder="请输入登录密码" v-model="formAddData.userPwd"></el-input>
                </el-form-item>
                <el-form-item label="企业名称：" prop="EnterpriseName">
                    <el-input disabled placeholder="请上传营业执照读取企业名称" v-model="formAddData.EnterpriseName"></el-input>
                </el-form-item>
                <el-form-item label="法人代表：" prop="EgalPersonName">
                    <el-input disabled placeholder="请上传营业执照读取法人代表" v-model="formAddData.EgalPersonName"></el-input>
                </el-form-item>
                <el-form-item label="注册号：" prop="RegistrationNumber">
                    <el-input disabled placeholder="请上传营业执照读取注册号" v-model="formAddData.RegistrationNumber"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-upload
                        :action="uploadUrl"
                        :on-change="handleChange"
                        multiple
                        :limit="1"
                        list-type="picture-card"
                        :on-success="(response, file,fileList)=> handleSuccess(response, file,fileList)"
                        :on-remove="(file,fileList)=> handlePicRemove(file, fileList)"
                        :file-list="uploadData"
                    ><i class="el-icon-plus"></i>
                    </el-upload>
                    <el-popover placement="right"
                                trigger="click">
                        <img :src="formAddData.BusinessLicense"
                             style="max-width:1000px;max-height: 90vh;border-radius:3px;">
                    </el-popover>
                </el-form-item>
                <p style="color:#e6a23c;margin-left:15%">请上传营业执照</p>


            </el-form>
            </el-card>
            <span slot="footer" class="dialog-footer">
            <el-button @click="hideDialogAddOrEdit">取 消</el-button>
            <el-button type="primary" :loading="formSumbitLoding" @click="formAddSumbit">提交</el-button>
          </span>
        </el-dialog>
        </el-card>
    </div>
</template>
<script>
    import {
        deleteDailyNew,
        batchAddDailyNew,
        getHatchUser, // 分页查询孵化团队成员列表
        getHatchUserB
    } from "../../api/incubationTeam/incubationTeam";
    import {
        setupUser,
        getCode, // 获取验证码
        businessLicenseOcr // 营业执照识别读取
    } from "../../api/mbuser/mbuser";
    import {BASE_URL} from "../../config/app";
    /*用作表单的数据初始化*/
    const formJson = {
        ids: ""
    };

    export default {
        components: {},
        data() {
            var checkPhone = (rule, value, callback) => {
                if (!value) {
                    return callback(new Error("手机号不能为空"));
                } else {
                    const reg = /^1[3|4|5|7|8][0-9]\d{8}$/;
                    console.log(reg.test(value));
                    if (reg.test(value)) {
                        callback();
                    } else {
                        return callback(new Error("请输入正确的手机号"));
                    }
                }
            };
            return {
                uploadUrl: BASE_URL + '/goldendays-currency/tool/uploadpro',//BASE_URL + '/tool/uploadpro', //上传图片
                uploadData: [],
                query: {
                    currentPage: 1,
                    searchParams: "",
                    InvitationCode: "",
                    pageSize: 5
                },
                addForm: {
                    name: null
                },
                checkQuery: {
                    currentPage: 1,
                    searchParams: "",
                    userid: "",
                    pageSize: 5
                },
                commodityIdArr: [],
                checkTotalNumber: 0, //分页总页数
                formName: null,
                formMap: {
                    add: "添加",
                    edit: "编辑"
                },
                merchantslist: [],
                merchantsgoodslist: [],
                list: [], //列表集合
                totalNumber: 0, //分页总页数
                loading: true, //列表加载
                checkLoading: false,
                formSumbitLoding: false, //表单提交加载
                cancelToggle: false, //列表是否全选
                multipleSelection: [], //多选集合
                dialogAddOrEdit: false, //新增或编辑弹框开关
                dialogAdd: false, // 添加孵化团队窗口
                dialogAddOrEditName: "", //新增或编辑弹框名字
                formData: formJson, //新增或修改的对象
                formAddData: {
                    IslegalPerson: 0, // 否是法人
                    userName: null, // 用户名称
                    userMobile: null, // 试机号码
                    userCode: null, // 手机验证码
                    userPwd: null, // 登录密码
                    EnterpriseName: null, // 企业名称
                    EgalPersonName: null, // 法人代表
                    RegistrationNumber: null, // 注册号
                    BusinessLicense: null // 营业执照图片路径
                },
              rules: {
                    //表单校验
                    IslegalPerson: {
                        required: true,
                        message: "是否是法人",
                        trigger: "blur"
                    },
                    userName: {
                        required: true,
                        message: "请输入真实姓名",
                        trigger: "blur"
                    },
                    userMobile: {
                        required: true,
                        validator: checkPhone,
                        message: "请输入手机号",
                        trigger: "blur"
                    },
                    userCode: {
                        required: true,
                        message: "请输入验证码",
                        trigger: "blur"
                    },
                    userPwd: {
                        required: true,
                        message: "请输入密码",
                        trigger: "blur"
                    },
                    EnterpriseName: {
                        required: true,
                        message: "上传营业执照读取企业名称",
                        trigger: "blur"
                    },
                    EgalPersonName: {
                        required: true,
                        message: "上传营业执照读取企业法人",
                        trigger: "blur"
                    },
                    RegistrationNumber: {
                        required: true,
                        message: "上传营业执照读取企业注册号",
                        trigger: "blur"
                    },
                    BusinessLicense: {
                        required: true,
                        message: "请上传营业执照",
                        trigger: "blur"
                    }
                },
                addRules: {
                    name: {
                        required: true,
                        message: "请输入孵化团队账号",
                        trigger: "blur"
                    }
                },
                addIncubationTeam: false, // 添加孵化团队
                disabled: false, // 获取验证码按钮的状态
                btntxt: "获取验证码", // 获取验证码按钮的的文字
                time: 0, // 获取验证码倒计时
                allLoading: false,
                formAddstats:true
            };
        },

        methods: {
            //上传图片
            handleSuccess(response, file) {
                // console.log(this.uploadData);
                if (response.status === 1) {
                    const filePath = response.data;
                    this.formAddData.BusinessLicense = filePath;
                    this.businessLicenseOcr();
                    return;
                }
                // console.log(file);
                this.$message.error("上传文件报错");
            },

            // 移除图片
            handlePicRemove(file, fileList) {
                console.log(file);
                console.log(fileList);
                this.formAddData.BusinessLicense = null;
            },

            handleChange(file, fileList) {
                this.uploadData = [fileList[fileList.length - 1]]; // 覆盖
                this.formAddData.BusinessLicense = null;
                return false;
            },

            /*获取列表事件*/
            getHatchUser() {
                this.loading = true;
                //   getTopList
                let formData = new FormData();
                Object.keys(this.query).forEach(key => {
                    formData.append(key, this.query[key]);
                });
                getHatchUser(formData)
                    .then(response => {
                        if (response.code != 0) {
                            this.$message.error(response.message);
                            this.loading = false;
                            return false;
                        }
                        console.log(response);
                        this.list = response.data.list || [];
                        this.totalNumber = response.data.totalNumber || 0;
                        setTimeout(() => {
                            this.loading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        this.loading = false;
                        this.list = [];
                    });
            },

            /*新增或者编辑提交事件*/
            formSumbit() {
                //表单校验通过
                let commodityIds = this.commodityIdArr.toString();
                this.formData.commodityIds = commodityIds;
                console.info(this.formData);
                this.$refs["ruleForm"].validate(valid => {
                    // console.log(valid)
                    if (valid) {
                        this.formSumbitLoding = true;
                        this.formData.inputdata = JSON.stringify(this.formData);
                        batchAddDailyNew(this.formData)
                            .then(response => {
                                this.formSumbitLoding = false;
                                if (response.code != 0) {
                                    this.$message.error(response.message);
                                    return false;
                                }
                                this.merchantsgoodslist = [];
                                this.checkTotalNumber = 0;
                                this.$message.success("操作成功");
                                this.hideDialogAddOrEdit();
                                // 加载表格数据
                                this.getHatchUser();
                            })
                            .catch(() => {
                                this.formSumbitLoding = false;
                            });
                    }
                });
                //new URLSearchParams(this.query)  提交数据格式不正确时可以转一下
            },

            closeCheck() {
                this.dialogAddOrEdit = false;
                this.merchantsgoodslist = [];
                this.checkTotalNumber = 0;
            },
            /*列表查询条件事件*/
            onSubmit() {
                this.query.currentPage = 1;
                this.getHatchUser();
            },

            /*刷新*/
            onRest() {
                //刷新事件需要重置查询条件
                this.query = {
                    currentPage: 1,
                    pageSize: 10
                };
                this.getHatchUser();
            },

            //显示 查看弹框
            detailForm(index, row) {
                if (row !== null) {
                    console.info(row);
                    this.dialogAddOrEdit = true;
                    this.formData = Object.assign({}, row);
                    let data = {
                        name: "",
                        url: ""
                    };
                    if (row.topcategorypic) {
                        this.uploadData = [];
                        let nameurl = row.topcategorypic;
                        data.url = nameurl;
                        data.name = nameurl.substring(nameurl.lastIndexOf("/") + 1);
                        this.uploadData.push(data);
                    }

                    this.dialogAddOrEditName = "编辑";
                }
            },

            /*显示 -新增或者编辑弹框*/
            showDialogAddOrEdit(row) {
                console.log(row);
                this.checkQuery.userid = row.userId;
                this.formData = Object.assign({}, formJson);
                this.dialogAddOrEdit = true;
                this.getHatchUserCheck();
            },

            /*显示 -新增或者编辑弹框*/
            showDialogAdd(index, row) {
                this.dialogAdd = true;
                this.formData = Object.assign({}, formJson); //将弹框内表单内容初始化
                if (row !== null) {
                    //如果row不为空，说明是修改，因为row是修改时携带过来此列的所有信息
                    this.formData = Object.assign({}, row); //修改则将列内容深拷贝到表单内容中
                    this.dialogAddOrEditName = "编辑";
                } else {
                    this.dialogAddOrEditName = "添加";
                }
            },

            //手机验证发送验证码
            sendcode() {
                // const reg = 11 && /^((13|14|15|17|18)[0-9]{1}\d{8})$/;
                if (this.formAddData.userMobile == "") {
                    this.$message({
                        message: "手机号不能为空",
                        center: true
                    });
                    return;
                }
                getCode({ userMobile: this.formAddData.userMobile, forwhat: 2 })
                    .then(response => {
                        if (response.code != 0) {
                            this.allLoading = false;
                            this.$message.error(response.message);
                            return false;
                        }
                        this.$message({
                            message: "发送成功",
                            type: "success",
                            center: true
                        });
                        this.time = 120;
                        this.disabled = true;
                        this.timer();
                        setTimeout(() => {
                            this.allLoading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        this.allLoading = false;
                    });
                // if (!reg.test(this.formAddData.userMobile)) {
                //     this.$message({
                //         message: "请输入正确的手机号",
                //         center: true
                //     });
                //     return;
                // } else {
                //     console.log(this.formAddData.userMobile);
                //     this.$message({
                //         message: "发送成功",
                //         type: "success",
                //         center: true
                //     });
                //     this.time = 60;
                //     this.disabled = true;
                //     this.timer();
                // }
            },
            //60S倒计时
            timer() {
                if (this.time > 0) {
                    this.time--;
                    this.btntxt = this.time + "s";
                    setTimeout(this.timer, 1000);
                } else {
                    this.time = 0;
                    this.btntxt = "获取验证码";
                    this.disabled = false;
                }
            },

            // 营业执照识别读
            businessLicenseOcr() {
                // debugger
                let formData = new FormData();
                let url = this.formAddData.BusinessLicense;
                formData.append("picUrl", url);
                this.allLoading = true;
                businessLicenseOcr(formData)
                    .then(response => {
                        console.info(response)
                        if (response.code != 0) {
                            this.allLoading = false;
                            this.$message.error(response.message);
                            return false;
                        }
                        if(response.data.requestId){
                            this.formAddData.EnterpriseName = response.data.name; // 企业名称
                            this.formAddData.EgalPersonName = response.data.person; // 法人代表
                            this.formAddData.RegistrationNumber = response.data.regNum; // 注册号
                            this.formAddData.BusinessLicense = url;
                            this.formAddData.IslegalPerson
                                ? (this.formAddData.IslegalPerson = 1)
                                : (this.formAddData.IslegalPerson = 0);
                            this.formAddstats=false;
                        }else {
                            this.formAddstats=true;
                            this.$message.error("请上传正确的营业执照！");

                        }
                        setTimeout(() => {
                            this.allLoading = false;
                        }, 0.3 * 1000);
                    })
                    .catch(() => {
                        this.allLoading = false;
                    });
            },
            formAddSumbit() {
                //表单校验通过
                this.$refs["formAddRules"].validate(valid => {
                    if (valid) {
                        this.formSumbitLoding = true;
                        var params = new URLSearchParams(this.formAddData);
                        console.info(this.formAddstats)
                        if(this.formAddstats){
                            this.$message.error("请上传正确的营业执照！");
                            this.formSumbitLoding = false;
                            return false;
                        }
                        setupUser(params).then(response => {
                            this.formLoading = false;
                            if (response.code != 0) {
                                this.$message.error(response.message);
                                this.formSumbitLoding = false;
                                return false;
                            }
                            this.formSumbitLoding = false;
                            this.dialogAdd = false;
                            this.formAddstats=false;
                            this.getHatchUser();
                            //隐藏弹框时需要清除弹框内容
                            if (this.$refs["formAddRules"]) {
                                this.$refs["formAddRules"].resetFields(); //清除formData表单
                                this.$refs["formAddRules"].clearValidate(); //清除表单验证
                            }
                            // 清空表单
                            this.$refs["formAddRules"].resetFields();
                        });
                    }
                });
                //new URLSearchParams(this.query)  提交数据格式不正确时可以转一下
            },
            // 添加提交按钮
            setupFormSubmit() {
                this.formLoading = true;
                let data = {
                    userid: this.formData.userid,
                    userentitytype: this.formData.userentitytype
                };
                var params = new URLSearchParams(data);
                setupUser(params).then(response => {
                    this.formLoading = false;
                    if (response.code != 0) {
                        this.$message.error(response.message);
                        this.formLoading = false;
                        return false;
                    }
                    this.$message.success("操作成功");

                    this.formLoading = false;
                    this.setupVisible = false;
                    // 清空表单
                    // this.$refs["dataForm"].resetFields();
                });
            },
            /*隐藏 -新增或编辑弹框*/
            hideDialogAddOrEdit() {
                this.dialogAddOrEdit = false;
                this.dialogAdd = false;
                this.merchantsgoodslist = [];
                //隐藏弹框时需要清除弹框内容
                if (this.$refs["ruleForm"]) {
                    this.$refs["ruleForm"].resetFields(); //清除formData表单
                    this.$refs["ruleForm"].clearValidate(); //清除表单验证
                }
                //如果上传文件，还需要清除文件列表
            },
            getHatchUserCheck() {
                let formData = new FormData();
                Object.keys(this.checkQuery).forEach(key => {
                    formData.append(key, this.checkQuery[key]);
                });
                getHatchUserB(formData)
                    .then(response => {
                        console.log(response);
                        if (response.code != 0) {
                            this.$message.error(response.message);
                            this.checkLoading = false;
                            return false;
                        }
                        this.checkLoading = false;
                        this.checkTotalNumber = response.data.totalNumber || 0;
                        this.merchantsgoodslist = response.data.list || [];
                        console.log(this.merchantsgoodslist);
                    })
                    .catch(() => {
                        this.checkLoading = false;
                        this.merchantsgoodslist = [];
                    });
            },

            /*点击页数*/
            handleCurrentChange(val) {
                this.query.currentPage = val;
                this.getHatchUser();
            },

            /*选择每页条数【10,20,30,40,50】*/
            handleSizeChange(val) {
                this.query.pageSize = val;
                this.getHatchUser();
            },
            /*弹窗 列表查询条件事件*/
            onCheckSubmit() {
                this.query.currentPage = 1;
                this.getHatchUserCheck();
            },
            /*弹窗 选择每页条数【10,20,30,40,50】*/
            checkHandleSizeChange(val) {
                this.checkQuery.pageSize = val;
                this.getHatchUserCheck(); // 重新查询列表
            },
            /*弹窗 点击页数*/
            checkHandleCurrentChange(val) {
                this.checkQuery.currentPage = val;
                this.getHatchUserCheck(); // 重新查询列表
            },
            /*弹窗 列表复选框选择事件*/
            checkHandleSelectionChange(val) {
                console.log(val);
                let arr = [];
                val.forEach((value, index) => {
                    console.log(index);
                    arr.push(value.commodityid);
                });
                this.commodityIdArr = arr;
            },
            /*取消全选事件*/
            toggleSelection(rows) {
                if (rows) {
                    rows.forEach(row => {
                        this.$refs.multipleTable.toggleRowSelection(row);
                    });
                } else {
                    this.$refs.multipleTable.clearSelection();
                }
            },

            /*列表复选框选择事件*/
            handleSelectionChange(val) {
                this.multipleSelection = val;
                if (val == "") {
                    this.cancelToggle = false;
                    return;
                }
                this.cancelToggle = true;
            },

            /*全选删除事件*/
            delGroup() {
                console.log(this.multipleSelection);
                var ids = this.multipleSelection
                    .map(item => item.dailynewid)
                    .join(); //获取所有选中行的id组成的字符串，以逗号分隔
                if (ids == "") {
                    this.$message({
                        message: "请先选择",
                        type: "warning"
                    });
                    return;
                }
                this.handleDel(ids);
            },

            /*单击删除事件*/
            handleDel(ids) {
                if (ids) {
                    this.$confirm("确认要删除吗?", "提示", {
                        type: "warning"
                    })
                        .then(() => {
                            this.loading = true;
                            var params = new URLSearchParams();
                            params.append("dailyNewIds", ids);
                            deleteDailyNew(params)
                                .then(response => {
                                    this.loading = false;
                                    if (response.code) {
                                        this.$message.error(response.message);
                                        return false;
                                    }
                                    this.$message.success("删除成功");
                                    // 刷新数据
                                    //this.list.splice(index, 1);
                                    this.getHatchUser();
                                })
                                .catch(() => {
                                    this.loading = false;
                                });
                        })
                        .catch(() => {
                            this.$message.warning("已取消");
                        });
                }
            },
            // 添加团队
            addIncubationTeamFun() {
                this.addIncubationTeam = true;
            },
            // 确认添加孵化对团
            addTeam(form) {
                this.$refs[form].validate(valid => {
                    if (valid) {
                        console.log("添加！");
                    }
                });
            },
            // 取消添加 表单重置
            cancelAddTeam(form) {
                this.addIncubationTeam = false;
                this.$refs[form].resetFields();
            },
            exportTeams(type) {
                // let formData = new FormData();
                if (type) {
                    // 导出当前列表
                    window.location.href =
                        // BASE_URL +
                        "http://192.168.1.149:8887/manage/hatch/exportdata?InvitationCode=" +
                        this.query.InvitationCode +
                        "&searchParams=" +
                        this.query.searchParams;
                } else {
                    // 导出下一级
                    window.location.href =
                        // BASE_URL +
                        "http://192.168.1.149:8887/manage/hatch/exportdata?InvitationCode=" +
                        this.checkQuery.InvitationCode +
                        "&searchParams=" +
                        this.checkQuery.searchParams;
                }
                // exportdata(formData)
                //     .then(response => {
                //         if (response.code != 0) {
                //             this.$message.error(response.message);
                //             this.loading = false;
                //             return false;
                //         }
                //         this.$message.success("成功导出！");
                //         setTimeout(() => {
                //             this.loading = false;
                //         }, 0.3 * 1000);
                //     })
                //     .catch(err => {
                //         this.$message.error(err);
                //     });
            }
        },
        created() {
            this.getHatchUser();
        }
    };
</script>
<style lang="scss"  scoped>

    .el-table th>.cell{
        text-align: center !important;
    }

</style>
